import java.util.Arrays;

import ij.IJ;
import ij.ImagePlus;
import ij.plugin.filter.PlugInFilter;
import ij.process.ImageProcessor;


public class TestIj_Plugin implements PlugInFilter {


	public void run(ImageProcessor orig) {
		// get image size
       int w = orig.getWidth();
       int h = orig.getHeight();
       ImageProcessor copy = orig.duplicate();
       for (int v=1; v<=h-2; v++) {
           for (int u=1; u<=w-2; u++) {
               //compute filter result for position (u,v)
               int sum = 0;
               for (int j=-1; j<=1; j++) {
                   for (int i=-1; i<=1; i++) {
                       int p = copy.getPixel(u+i,v+j);
                       sum = sum + p;
                   }
               }
               int q = (int) (sum / 9.0);
               orig.putPixel(u,v,q);  
           }
       }
       IJ.showMessage("fini");
	}

	public int setup(String arg0, ImagePlus imp) {
	       if (arg0.equals("about")) {
	            showAbout();
	            return DONE;
	        }
		return DOES_8G;
	}

	private void showAbout() {
		// TODO Auto-generated method stub
        String cn = getClass().getName();
        IJ.showMessage("About "+cn+" ...",
            "IRSTV testing of ImageJ."
        );
		
	}

}
